﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using XbsWebAPI.Application;
using XbsWebAPI.Application.CampRoom.Room.Dtos;
using XbsWebAPI.Application.QueryModel;
using XbsWebAPI.EntityFrameworkCore.Entities;

namespace XbsWebAPI.MainHost.Controllers
{
    /// <summary>
    /// 房间管理
    /// </summary>
    [ApiController]
    [Route("api/xbs_v1/[controller]")]
    public class RoomController : Controller
    {
        private readonly IRoomAppService _roomAppService;

        public RoomController(IRoomAppService roomAppService)
        {
            _roomAppService = roomAppService;
        }

        /// <summary>
        /// 新建房间
        /// </summary>
        /// <param name="model">房间入参</param>
        /// <returns></returns>
        [HttpPost,Route("[action]")]
        public async Task<ResultDto<string>> AddRoom(CreateRoomDto model)
        {
            var result = await _roomAppService.CreateRoomAsync(model);
            return result;
        }

        /// <summary>
        /// 编辑房间
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("[action]")]
        public async Task<ResultDto<string>> EditRoom(EditRoomDto model)
        {
            var result = await _roomAppService.EditRoomAsync(model);

            return result;
                
         }

        /// <summary>
        /// 根据Id查询房间
        /// </summary>
        /// <param name="id">房间Id</param>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public ResultDto<GetRoomDto> FindRoom(Guid id)
        {
            var Room = _roomAppService.GetRoomById(id);

            return Room;
        }

        /// <summary>
        /// 分页查询房间
        /// </summary>
        /// <param name="name">房间名称</param>
        /// <param name="isEnabled">是否启用</param>
        /// <param name="pageNumber">第几页，默认1</param>
        /// <param name="pageSize">每页多少条，默认10</param>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public ResultDto<PageListDto<ListRoomDto>> FindRoomPagedList(string name,bool? isEnabled,int? pageNumber,int? pageSize)
        {
            QueryRoom query = new QueryRoom
            {
                Name = name,
                IsEnabled = isEnabled,
                PageNumber = pageNumber,
                PageSize = pageSize
            };
            var result = _roomAppService.GetPagedList(query);

            return result;
        }

        /// <summary>
        /// 删除房间
        /// </summary>
        /// <param name="id">房间Id</param>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public async Task<ResultDto<string>> DeleteRoom(Guid id)
        {
            var result = await _roomAppService.RemoveRoomAsync(id);

            return result;
        }

        /// <summary>
        /// 启用/禁用 房间
        /// </summary>
        /// <param name="id">房间Id</param>
        /// <param name="isEnable">是否启用</param>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public async Task<ResultDto<string>> CheckRoomEnable(Guid id, bool isEnable)
        {
            var result = await _roomAppService.CheckRoomEnable(id, isEnable);

            return result;

        }

    }
}
